home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / misc / edu / Calgor.lha / Cal / CalSource / menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-22  |  29.8 KB  |  1,145 lines

  1. /* Copyright © 1995-1996 : David Atkinson */
  2. /* V1.21  Menus.c */
  3. /* Calgor */
  4.  
  5. #include <hold/extra.h>
  6. #include <hold/funchead.h>
  7.  
  8. #include <intuition/intuition.h>
  9.  
  10. #include <graphics/gfx.h>
  11. #include <graphics/gfxbase.h>
  12. #include <graphics/gfxmacros.h>
  13. #include <graphics/copper.h>
  14. #include <graphics/view.h>
  15. #include <graphics/text.h>
  16. #include <graphics/sprite.h>
  17.  
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <fcntl.h>
  21. #include <string.h>
  22. #include <signal.h>
  23.  
  24. #include <exec/libraries.h>
  25.  
  26. #include <graphics/gfxnodes.h>
  27. #include <graphics/displayinfo.h>
  28. #include <graphics/videocontrol.h>
  29. #include <clib/exec_protos.h>
  30. #include <clib/intuition_protos.h>
  31. #include <clib/graphics_protos.h>
  32. #include <clib/dos_protos.h>
  33. #include <clib/diskfont_protos.h>
  34. #include <utility/tagitem.h>
  35.  
  36. #ifdef(V3)
  37. #include <graphics/modeid.h>
  38. #endif
  39.  
  40. extern void get_source(char *);
  41. extern void handler(int);
  42. extern void showcode(void);
  43. extern void play_col(int);
  44. extern void ff_col(int);
  45. extern void clr_code(void);
  46. extern void killsprite(void);
  47. extern void clean_local(void);
  48. extern void al_clean(void);
  49. extern void clr_dem(void);
  50. extern void select(void);
  51. extern void set_sprite(void);
  52. extern void reset_sprites(void);
  53. extern void chk_view(struct View *, struct View *);
  54. extern SHORT anim_button(void);
  55. extern SHORT menu_button(void);
  56. extern void open_log(void);
  57. extern void close_file(void);
  58. extern void write_file(char *);
  59. extern void back_drop(void);
  60. extern void shutdown(void);
  61. extern void clearkeybuf(void);
  62. extern void draw_modes(UBYTE,struct RastPort *,long,long,UBYTE);
  63.  
  64. extern struct Window *my_window;
  65. extern struct Screen *my_screen;
  66. extern SHORT squeek[2];
  67. extern char *buffer, *display;
  68. extern int last;
  69. extern int dem_num;
  70. extern SHORT fraction;
  71. extern SHORT trip;
  72. extern struct GfxBase *ps;
  73. extern BOOL lmbpress;
  74. extern BOOL wactive;
  75. extern struct MsgPort *aport;
  76.  
  77. void cleanup(void);
  78. void alert(char *);
  79. void op_liblob(void);
  80. void viewstart(void);
  81. void viewportstart(void);
  82. void bit_init(void);
  83. void ras_init(void);
  84. void show_display(int);
  85. void menu_opt(void);
  86. void put_back(int);
  87. void close_display(void);
  88. void acquire_bits(int);
  89. void get_palette(int);
  90. void get_editor(void);
  91. void copy_object(int, long, long, struct BitMap * );
  92. void opttext(void);
  93. void write_opt(int,long);
  94. void anim_opt(void);
  95.  
  96. struct Library *IntuitionBase = NULL;
  97. struct Library *DiskfontBase = NULL;
  98. struct Library *ConsoleDevice = NULL;
  99. struct Library *WorkbenchBase = NULL;
  100. struct GfxBase *GfxBase = NULL;
  101. struct BitMap ft_bitmap = { NULL };
  102. struct BitMap sec_bitmap= { NULL };
  103. struct BitMap thd_bitmap= { NULL };
  104. struct ViewPort ft_viewport = { NULL };
  105. struct ViewPort sec_viewport= { NULL };
  106. struct View ft_view = { NULL };
  107. struct View sec_view = { NULL };
  108. struct RastPort ft_rastport = { NULL };
  109. struct RastPort sec_rastport = { NULL };
  110. struct RastPort thd_rastport = { NULL };
  111. struct View *old_view = NULL;
  112. struct RasInfo ft_rasinfo = { NULL };
  113. struct RasInfo sec_rasinfo = { NULL };
  114. struct RasInfo thd_rasinfo = { NULL };
  115. struct GfxBase *wb = NULL;
  116. /* For 2.0+ Wb */
  117. struct ViewExtra *ft_vextra=NULL;
  118. struct ViewExtra *sec_vextra=NULL;
  119. struct MonitorSpec *monspec=NULL;
  120. struct ViewPortExtra *vpone_extra=NULL;
  121. struct ViewPortExtra *vptwo_extra=NULL;
  122. struct DimensionInfo dimquery = { NULL };
  123. struct MonitorInfo monstuff = { NULL };
  124. struct DisplayInfo distuff = { NULL };
  125. UWORD vpone_col[COLOURS],vptwo_col[COLOURS];
  126. ULONG modeID = 0;
  127.  
  128. UWORD colour_table[VYOUS][COLOURS];  /* Colour Palette */
  129. char choices[NUMOFOPT][SLENGTH];     /* Options */
  130. char editor[MAXCHARPATH];            /* Editor Buffer */
  131. UWORD wb_version = 37;               /* WorkBench version, fixed at 37 for now  */
  132. int old_dem=0;                       /* Dem_num changes a bit, old_dem doesn't */
  133. UBYTE *keybufptr = NULL;             /* Keyboard buffer */
  134. struct ColorMap *cm = NULL;          /* Color map pointer for view one */
  135. struct ColorMap *cmtwo = NULL;       /* Colour map pointer for view two */
  136. struct IOStdReq ioreq = { NULL };
  137. struct TagItem voneTags[4] =
  138. {
  139.     { VTAG_ATTACH_CM_SET, NULL },
  140.     { VTAG_VIEWPORTEXTRA_SET, NULL },
  141.     { VTAG_NORMAL_DISP_SET, NULL },
  142.     { VTAG_END_CM, NULL }
  143. };
  144.  
  145. struct TagItem vtwoTags[4] =
  146. {
  147.     { VTAG_ATTACH_CM_SET, NULL },
  148.     { VTAG_VIEWPORTEXTRA_SET, NULL },
  149.     { VTAG_NORMAL_DISP_SET, NULL },
  150.     { VTAG_END_CM, NULL }
  151. };
  152.  
  153. struct TextFont *font_ptr = NULL;
  154. struct TextFont *cfontptr = NULL;
  155.  
  156. struct TextAttr opt_font =
  157. {
  158.   "helvetica.font",
  159.   13,
  160.   FS_NORMAL,
  161.   FPF_DISKFONT | FPF_DESIGNED
  162. };
  163.  
  164. struct TextAttr code_font =
  165. {
  166.   "topaz.font",
  167.   8,
  168.   FS_NORMAL,
  169.   FPF_ROMFONT
  170. };
  171.  
  172. /* void op_liblob(void)
  173.    Opens up the amigas librarys, shuts down cpu datacaches, sets up modeid, opens
  174.    console Device, sets up input handler, opens fonts and gets memory for  keyboard buffer.
  175.    The OpenLibray routines not needed in Dice but needed in SAS/C */
  176.  
  177. void op_liblob()
  178. {
  179. SHORT result=0;
  180.  
  181.   /* Fix for 68030, when on low amount of memory (chip), get problem writing text
  182.      to sreen. See corresponding cpu command in cleanup */
  183.  
  184.   result=system("cpu nodatacache > NIL:");
  185.   IntuitionBase = OpenLibrary("intuition.library",0);
  186.   if (IntuitionBase == 0)
  187.     alert("Failed to open intuition library (op_liblob)\n");
  188.   WorkbenchBase = OpenLibrary("workbench.library",37);
  189.   if(WorkbenchBase == 0)
  190.     alert("Failed to open workbench library 37+ (op_liblob)\n");
  191.   GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 0 );
  192.   if (GfxBase==0)
  193.     alert("Failed to open graphics library (op_liblob)\n");
  194.   wb_version = GfxBase->LibNode.lib_Version;
  195.   if(wb_version < 37)
  196.      alert("Sorry Need WorkBench 37+ To Run\n");
  197.   wb_version=37;   /* Fix it for now */
  198.   DiskfontBase = OpenLibrary("diskfont.library", 0 );
  199.   if (DiskfontBase==0)
  200.     alert("Failed to open diskfont library (op_liblob)\n");
  201.  
  202.   wb = (struct GfxBase *) GfxBase;
  203.   if( wb_version<39 ){
  204.     modeID = PAL_MONITOR_ID | HIRESLACE_KEY;
  205.   }
  206.   else{
  207.     modeID = PAL_MONITOR_ID | HIRESLACE_KEY;
  208.     #ifdef(V3)
  209.     modeID = DBLPAL_MONITOR_ID | DBLPALHIRESFF_KEY;
  210.     #endif
  211.   }
  212.   old_view = wb->ActiView;
  213.   /* Open Console Device */
  214.   if (0==OpenDevice("console.device",-1,(struct IORequest *) &ioreq, 0) ){
  215.     ConsoleDevice = (struct Library *) ioreq.io_Device;
  216.   }
  217.   else{
  218.     alert("Failed to open console device (op_liblob)\n");
  219.   }
  220.   signal(SIGINT,handler);
  221.   keybufptr=(UBYTE *) malloc(KEYBUFF);
  222.   if(keybufptr==NULL){
  223.     alert("Failed to allocate memory for keyboard buffer (op_liblob)\n");
  224.   }
  225.   if( !(aport = CreateMsgPort()) ){
  226.     alert("Failed to open message port\n");
  227.   }
  228.   font_ptr=OpenDiskFont(&opt_font);
  229.   if(font_ptr==NULL){
  230.     opt_font.ta_Name = "times.font";
  231.     opt_font.ta_YSize = 11;
  232.     font_ptr=OpenDiskFont(&opt_font);
  233.   }
  234.   if(font_ptr==NULL){
  235.     opt_font.ta_Name = "courier.font";
  236.     opt_font.ta_YSize = 11;
  237.     font_ptr=OpenDiskFont(&opt_font);
  238.   }
  239.   if(font_ptr==NULL){                  /* PaniC - Find A font */
  240.     opt_font.ta_Name = "napsa.font";
  241.     opt_font.ta_YSize = 11;
  242.     font_ptr=OpenDiskFont(&opt_font);
  243.   }
  244.   if(font_ptr==NULL){
  245.      alert("Couldn't Open Font:  Need helvetica 13 or times 11 or courier 11 or napsa 11\n");
  246.   }
  247.   cfontptr = OpenFont(&code_font);
  248.   if(cfontptr==NULL){
  249.     alert("Couldn't Open topaz.font (8) (op_liblob)\n");
  250.   }
  251. }
  252.  
  253. /* void get_palette(int)
  254.    get_palette, reads in palette colours (long words) from
  255.    specified file path number. Have to cast from int to UWORD
  256.    for the palette arrays */
  257.  
  258. void get_palette(int palnum)
  259. {
  260. char *palete_file;
  261. FILE *fp=NULL;
  262. int i,col_tab[COLOURS];
  263.  
  264.   switch(palnum){
  265.     case(1):
  266.       palete_file=MENUPALETE;
  267.       break;
  268.     case(2):
  269.       palete_file=DEMPALETE;
  270.       break;
  271.     default:
  272.       clean_local();
  273.       alert("Incorrect Menu label (get_pallete)\n");
  274.       break;
  275.   }
  276.  
  277.   fp = fopen(palete_file,"r");
  278.   if ( fp ){
  279.     for(i=0;i<COLOURS;i++){
  280.       fscanf(fp,"%x",&col_tab[i]);
  281.       /*We have to cast */
  282.       colour_table[palnum-1][i] = (UWORD) col_tab[i];
  283.     }
  284.     fclose( fp );
  285.   }
  286.   else {
  287.     clean_local();
  288.     alert("Couldn't open palette (get_pallete)\n");
  289.   }
  290. }
  291.  
  292. void get_editor(void){
  293. FILE *edfp=NULL;
  294.  
  295.   edfp = fopen(EDITPATH,"r");
  296.   if(edfp){
  297.     fscanf(edfp,"%s",editor);
  298.     fclose(edfp);
  299.   }
  300.   else{
  301.     printf("Failed open data/editor.dat: Defaulting to sys:utilities/multiview \n");
  302.     strcpy(editor,ONETWO);
  303.   }
  304. }
  305.  
  306. /* void viewstart(void)
  307.    viewstart initialises the view structure and modes
  308.    LACE, HIRES, 640*512. Note the view structue Dxoffsets
  309.    and DyOffsets are initialised not necasarily set to 0,
  310.    presently set to 129*44. (V1.3)  */
  311.  
  312. void viewstart()
  313. {
  314.   /* 1.3 Wb */
  315.   InitView(&ft_view);
  316.   if(wb_version>=36){
  317.     ft_view.DxOffset = 0; /* For 2.0+ have to get XY values from monitor database */
  318.     ft_view.DyOffset = 0;
  319.   }
  320.   ft_view.Modes = LACE|HIRES|SPRITES;
  321.   ft_view.ViewPort = &ft_viewport;
  322.   InitView(&sec_view);
  323.   sec_view.ViewPort =&sec_viewport;
  324.   sec_view.Modes = LACE|HIRES|SPRITES;
  325.   if(wb_version>=36){
  326.     sec_view.DxOffset = 0;
  327.     sec_view.DyOffset = 0;
  328.   }
  329.   /* 2.0+ Wb */
  330.   if(wb_version>=36){
  331.     ft_vextra=GfxNew(VIEW_EXTRA_TYPE);
  332.     sec_vextra=GfxNew(VIEW_EXTRA_TYPE);
  333.     if( ! ((ft_vextra == NULL) || (sec_vextra==NULL)) ){
  334.       GfxAssociate(&ft_view, ft_vextra);
  335.       ft_view.Modes  = LACE|HIRES|SPRITES|EXTEND_VSTRUCT;
  336.       GfxAssociate(&sec_view, sec_vextra);
  337.       sec_view.Modes = LACE|HIRES|SPRITES|EXTEND_VSTRUCT;
  338.       if(monspec=OpenMonitor(NULL,modeID) ){
  339.         ft_vextra->Monitor=monspec;
  340.         sec_vextra->Monitor=monspec;
  341.       }
  342.       else{
  343.         clean_local();
  344.         alert("Could not get Monitor Spec (viewstart)\n");
  345.       }
  346.     }
  347.     else{
  348.        clean_local();
  349.        alert("Could not allocate viewextra (viewstart)\n");
  350.     }
  351.   }
  352. }
  353.  
  354. /* void viewportstart(void)
  355.    Initiliases the viewport structure. DX and DY Offsets are
  356.    set to 0 (by InitVPort) (wb1.3).  I have selected hires and interlace
  357.    modes. Remember to initialise the colour table before issuing
  358.    this function. */
  359.  
  360. void viewportstart()
  361. {
  362. UWORD *colorptr=NULL;
  363.  
  364. int loop;
  365. ULONG size;
  366.  
  367.   for(loop=0;loop<COLOURS;loop++){
  368.     vpone_col[loop]=colour_table[0][loop];
  369.     vptwo_col[loop]=colour_table[1][loop];
  370.   }
  371.   InitVPort(&ft_viewport);
  372.   ft_viewport.Next = NULL;
  373.   ft_viewport.DWidth = WIDTH;
  374.   ft_viewport.DHeight = HEIGHT;
  375.   ft_viewport.Modes = LACE|HIRES|SPRITES;
  376.   ft_viewport.RasInfo = &ft_rasinfo;
  377.   /* 2.0+ */
  378.   cm = (struct ColorMap *) GetColorMap( COLOURS * 2 );
  379.   if(cm==NULL){
  380.     clean_local();
  381.     alert("Couldn't allocate first colour map (viewportstart)\n");
  382.   }
  383.   if(wb_version>=36){
  384.     ft_viewport.Modes=LACE|HIRES|SPRITES|EXTEND_VSTRUCT;
  385.     vpone_extra=GfxNew(VIEWPORT_EXTRA_TYPE);
  386.     if(vpone_extra!=NULL){
  387.       voneTags[1].ti_Data = (ULONG) vpone_extra;
  388.       size = (ULONG) sizeof(monstuff);
  389.       /* Get Monitor Details */
  390.       if(GetDisplayInfoData(NULL,(UBYTE *) &monstuff,size,DTAG_MNTR,modeID) == 0){
  391.         clean_local();
  392.         alert("Couldn't access display database - MonitorInfo (viewportstart)\n");
  393.       }
  394.       size = (ULONG) sizeof(distuff);
  395.       /* Get Display Details */
  396.       if(GetDisplayInfoData(NULL,(UBYTE *) &distuff,size,DTAG_DISP,modeID) == 0){
  397.         clean_local();
  398.         alert("Couldn't access display database - MonitorInfo (viewportstart)\n");
  399.       }
  400.       /* Putting correct monitor positions */
  401.       ft_view.DxOffset = sec_view.DxOffset = monstuff.ViewPosition.x;
  402.       ft_view.DyOffset = sec_view.DyOffset = monstuff.ViewPosition.y;
  403.       size = (ULONG) sizeof(dimquery);
  404.       /* Get dimension details */
  405.       if(GetDisplayInfoData(NULL,(UBYTE *) &dimquery,size,DTAG_DIMS,modeID) != 0){
  406.         vpone_extra->DisplayClip = dimquery.Nominal;
  407.         voneTags[2].ti_Data = (ULONG) FindDisplayInfo(modeID);
  408.         if(voneTags[2].ti_Data == NULL){
  409.           clean_local();
  410.           alert("Could not get the DimensionInfo (viewportstart)\n");
  411.         }
  412.       }
  413.       else{
  414.         clean_local();
  415.         alert("Could not get DimensionInfo (viewportstart)\n");
  416.       }
  417.     }
  418.     else{
  419.       clean_local();
  420.       alert("Couldn't allocate viewport1 extra (viewportstart)\n");
  421.     }
  422.     voneTags[0].ti_Data = (ULONG) &ft_viewport;
  423.     if( VideoControl(cm,voneTags)!=NULL ){
  424.       clean_local();
  425.       alert("Could not attach ft_viewport (viewportstart)\n");
  426.     }
  427.     LoadRGB4(&ft_viewport,vpone_col,16);
  428.   }
  429.   else{
  430.     ft_viewport.ColorMap = cm;
  431.   }
  432.   InitVPort(&sec_viewport);
  433.   sec_viewport.Next = NULL;
  434.   sec_viewport.DWidth = WIDTH;
  435.   sec_viewport.DHeight = HEIGHT;
  436.   sec_viewport.Modes = HIRES|LACE|SPRITES;
  437.   sec_viewport.RasInfo = &sec_rasinfo;
  438.   cmtwo = (struct ColorMap *) GetColorMap( COLOURS * 2 ); /* Was X2 */
  439.   if(cmtwo==NULL){
  440.     clean_local();
  441.     alert("Couldn't alloacte second color map (viewportstart)\n");
  442.   }
  443.   if(wb_version>=36){
  444.     sec_viewport.Modes=LACE|HIRES|SPRITES|EXTEND_VSTRUCT;
  445.     if(vptwo_extra = GfxNew(VIEWPORT_EXTRA_TYPE) ) {
  446.       vtwoTags[1].ti_Data = (ULONG) vptwo_extra;
  447.       vptwo_extra->DisplayClip = dimquery.Nominal;
  448.       if( !(vtwoTags[2].ti_Data = (ULONG) FindDisplayInfo(modeID) ) ){
  449.          clean_local();
  450.          alert("Could not get the DisplayInfo (viewportstart)\n");
  451.       }
  452.     }
  453.     else{
  454.       clean_local();
  455.       alert("Couldn't allocate viewport extra (viewportstart)\n");
  456.     }
  457.     vtwoTags[0].ti_Data = (ULONG) &sec_viewport;
  458.     if( VideoControl(cmtwo,vtwoTags) ){
  459.       clean_local();
  460.       alert("Could not attach sec_viewport (viewportstart)\n");
  461.     }
  462.     LoadRGB4(&sec_viewport,vptwo_col,16);
  463.   }
  464.   else{
  465.     sec_viewport.ColorMap = cmtwo;
  466.     colorptr =(UWORD *) ft_viewport.ColorMap->ColorTable;
  467.     for (loop=0;loop<COLOURS;loop++){
  468.       *colorptr++ = colour_table[0][loop];
  469.     }
  470.     colorptr =(UWORD *) sec_viewport.ColorMap->ColorTable;
  471.     for (loop=0;loop<COLOURS;loop++){
  472.       *colorptr++ = colour_table[1][loop];
  473.     }
  474.   }
  475. }
  476.  
  477. void bit_init()
  478. {
  479. int loop;
  480.  
  481. /* The WaitBlits are a stab at trying to fix the text corruption problem */
  482.  
  483.   InitBitMap( &ft_bitmap, DEPTH, WIDTH, HEIGHT );
  484.   for( loop = 0; loop < DEPTH; loop++ )
  485.   {
  486.     ft_bitmap.Planes[ loop ] = AllocRaster( WIDTH, HEIGHT );
  487.     if( ft_bitmap.Planes[ loop ] == NULL )
  488.       alert("Failed Bitmap allocation 1 (bit_init)\n");
  489.     WaitBlit();
  490.     BltClear( ft_bitmap.Planes[ loop ],
  491.            RASSIZE( WIDTH, HEIGHT ), 0 );
  492.   }
  493.   WaitBlit();
  494.   InitBitMap( &sec_bitmap, DEPTH, WIDTH, HEIGHT );
  495.   for( loop = 0; loop < DEPTH; loop++ )
  496.   {
  497.     sec_bitmap.Planes[ loop ] = AllocRaster( WIDTH, HEIGHT );
  498.     if( sec_bitmap.Planes[ loop ] == NULL )
  499.       alert("Failed Bitmap allocation 2 (bit_init)\n");
  500.     WaitBlit();
  501.     BltClear( sec_bitmap.Planes[ loop ],
  502.            RASSIZE( WIDTH, HEIGHT ), 0 );
  503.   }
  504.   WaitBlit();
  505.   InitBitMap( &thd_bitmap, DEPTH, WIDTH, HEIGHT );
  506.   for( loop = 0; loop < DEPTH; loop++ )
  507.   {
  508.     thd_bitmap.Planes[ loop ] = AllocRaster( WIDTH, HEIGHT );
  509.     if( thd_bitmap.Planes[ loop ] == NULL )
  510.       alert("Failed Bitmap allocation 3 (bit_init)\n");
  511.     WaitBlit();
  512.     BltClear( thd_bitmap.Planes[ loop ],
  513.            RASSIZE( WIDTH, HEIGHT ), 0 );
  514.   }
  515.   WaitBlit();
  516. }
  517.  
  518. void ras_init()
  519. {
  520.   ft_rasinfo.BitMap = &ft_bitmap;
  521.   ft_rasinfo.RxOffset = RX_OFFSET;
  522.   ft_rasinfo.RyOffset = RY_OFFSET;
  523.   ft_rasinfo.Next = NULL;
  524.   InitRastPort(&ft_rastport);
  525.  
  526.   ft_rastport.BitMap=&ft_bitmap;
  527.   ft_rastport.Mask = 0xFF;
  528.  
  529.   sec_rasinfo.BitMap = &sec_bitmap;
  530.   sec_rasinfo.RxOffset = RX_OFFSET;
  531.   sec_rasinfo.RyOffset = RY_OFFSET;
  532.   sec_rasinfo.Next = NULL;
  533.   InitRastPort(&sec_rastport);
  534.   sec_rastport.BitMap=&sec_bitmap;
  535.   sec_rastport.Mask = 0xFF;
  536.  
  537.   thd_rasinfo.BitMap = &thd_bitmap;
  538.   thd_rasinfo.RxOffset = RX_OFFSET;
  539.   thd_rasinfo.RyOffset = RY_OFFSET;
  540.   thd_rasinfo.Next = NULL;
  541.   InitRastPort(&thd_rastport);
  542.   thd_rastport.BitMap=&thd_bitmap;
  543. }
  544.  
  545. void show_display(int vselect)
  546. {
  547.   switch(vselect){
  548.     case(1):
  549.       MakeVPort(&ft_view, &ft_viewport );
  550.       MrgCop(&ft_view);
  551.       LoadView(&ft_view);
  552.       break;
  553.     case(2):
  554.       MakeVPort(&sec_view, &sec_viewport );
  555.       MrgCop(&sec_view);
  556.       LoadView(&sec_view);
  557.       set_sprite();
  558.       reset_sprites();
  559.       break;
  560.     default:
  561.       clean_local();
  562.       alert("Failed view selection (prep_hardware)\n");
  563.       break;
  564.   }
  565. }
  566.  
  567. /* The status when we hit this routine is that the second view and viewport
  568.    are showing */
  569.  
  570. void anim_opt(void)
  571. {
  572. char filename[MAXCHARPATH];
  573. SHORT butpress=0;
  574. ULONG check;
  575.  
  576.    old_dem=dem_num;
  577.    show_display(2);
  578.    while(dem_num!=-1){
  579.  
  580.       check = LockIBase(0);
  581.       ps = (struct GfxBase *) GfxBase;
  582.       UnlockIBase(check);
  583.       chk_view(ps->ActiView,&sec_view);
  584.      raise(SIGINT);
  585.      butpress = anim_button();
  586.      clearkeybuf();
  587.      #ifdef(TEST)
  588.        squeek[1] = 27;
  589.        squeek[0] = 19;
  590.        wactive=lmbpress=TRUE;
  591.        dem_num=old_dem = 4;
  592.        butpress = PLAYBUT;
  593.      #endif
  594.  
  595.      switch(butpress){
  596.        case PLAYBUT : case NUM1KEY :
  597.          /*  PLAY BUTTON */
  598.          dem_num=old_dem;
  599.          strcpy(filename,ONEONE);
  600.          strcat(filename,&choices[8+(old_dem*2)][0]);
  601.          strcat(filename,".c");
  602.          clr_code();
  603.          clr_dem();
  604.          reset_sprites();
  605.          play_col(1);
  606.          get_source(filename);
  607.          showcode();
  608.          switch (dem_num){
  609.            case 100:
  610.              break;
  611.            case 1:
  612.              ifelse_control();
  613.              break;
  614.            case 2 :
  615.              switch_control();
  616.              break;
  617.            case 3 :
  618.              for_control();
  619.              break;
  620.            case 4 :
  621.              while_control();
  622.              break;
  623.            case 5 :
  624.              dowhile_control();
  625.              break;
  626.            case 6:
  627.              array_control();
  628.              break;
  629.            case 11 :
  630.              bubble_control();
  631.              break;
  632.            case 12 :
  633.              insert_control();
  634.              break;
  635.            case 13 :
  636.              select_control();
  637.              break;
  638.            case 14 :
  639.              quick_control();
  640.              break;
  641.            case 21:
  642.              user1_control();
  643.              break;
  644.            case 22:
  645.              user2_control();
  646.              break;
  647.            case 23:
  648.              user3_control();
  649.              break;
  650.            case 24:
  651.              user4_control();
  652.              break;
  653.            case 25:
  654.              user5_control();
  655.              break;
  656.            default :
  657.              clean_local();
  658.              printf("Falied to lock %d\n",dem_num);
  659.              alert("Failed to get opt num (anim_opt)\n");
  660.              break;
  661.            }
  662.            play_col(0);
  663.            ff_col(0);
  664.            #ifdef TEST
  665.              clean_local();
  666.              alert("Finished test\n");
  667.            #endif
  668.            break;
  669.          case EJECTBUT : case ESCKEY :
  670.            /* EJECT BUTTON */
  671.            clean_local();
  672.            clr_code();
  673.            clr_dem();
  674.            dem_num=-1;
  675.            show_display(1);
  676.            break;
  677.          case INFOBUT : case NUM5KEY :
  678.            /* INFORMATION BUTTON */
  679.            killsprite();
  680.            shutdown();
  681.            LoadView(old_view);
  682.            strcpy(filename,editor);
  683.            strcat(filename," ");
  684.            strcat(filename,ONETHREE);
  685.            strcat(filename,&choices[8+(old_dem*2)][0]);
  686.            strcat(filename,".txt");
  687.            system(filename);
  688.            back_drop();
  689.            LoadView(&sec_view);
  690.            set_sprite();
  691.            reset_sprites();
  692.            break;
  693.         default :
  694.            break;
  695.      }
  696.    }
  697. }
  698.  
  699. void menu_opt(void)
  700. {
  701. ULONG chit;
  702. SHORT key=0;
  703.  
  704.   while(dem_num==-1){
  705.       chit = LockIBase(0);
  706.       ps = (struct GfxBase *) GfxBase;
  707.       UnlockIBase(chit);
  708.       chk_view(ps->ActiView,&ft_view);
  709.       raise(SIGINT);
  710.       key=menu_button();
  711.       clearkeybuf();
  712.       /* F1 Option 1 */
  713.       if ( (key==F1BUTTON) && (last!=0)  ){
  714.          copy_object(1,55,93,&ft_bitmap);
  715.          put_back(last);
  716.          last=0;
  717.          write_opt(0,MBLACK);
  718.       }
  719.       /* F2 Option 2 */
  720.       if ( (key==F2BUTTON) && (last!=1) ){
  721.          copy_object(1,169,93,&ft_bitmap);
  722.          put_back(last);
  723.          last=1;
  724.          write_opt(1,MBLACK);
  725.       }
  726.  
  727.       /* F3 Option 3 */
  728.      if ( (key==F3BUTTON) && (last!=2) ){
  729.         copy_object(1,283,93,&ft_bitmap);
  730.         put_back(last);
  731.         last=2;
  732.         write_opt(2,MBLACK);
  733.      }
  734.  
  735.      /* F4 Option 4 */
  736.      if ( (key==F4BUTTON) && (last!=3) ){
  737.         copy_object(1,397,93,&ft_bitmap);
  738.         put_back(last);
  739.         last=3;
  740.         write_opt(3,MBLACK);
  741.      }
  742.  
  743.      /* F5 Option 5 */
  744.      if ( (key==F5BUTTON) && (last!=4) ){
  745.         copy_object(1,511,93,&ft_bitmap);
  746.         put_back(last);
  747.         last=4;
  748.         write_opt(4,MBLACK);
  749.      }
  750.  
  751.      /* Scan y coords for key options */
  752.      #ifdef(TEST)
  753.         last=0;
  754.         key = NUM4KEY;
  755.      #endif
  756.      switch(key){
  757.        case NUM1KEY:
  758.          dem_num=(last*5+1);
  759.          if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
  760.            anim_opt();
  761.          else
  762.            dem_num=-1;
  763.          break;
  764.        case NUM2KEY:
  765.          dem_num=(last*5+2);
  766.          if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
  767.            anim_opt();
  768.          else
  769.            dem_num=-1;
  770.          break;
  771.        case NUM3KEY:
  772.          dem_num=(last*5+3);
  773.          if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
  774.            anim_opt();
  775.          else
  776.            dem_num=-1;
  777.          break;
  778.        case NUM4KEY:
  779.          dem_num=(last*5+4);
  780.          if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
  781.            anim_opt();
  782.          else
  783.            dem_num=-1;
  784.          break;
  785.        case NUM5KEY:
  786.          dem_num=(last*5+5);
  787.          if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
  788.            anim_opt();
  789.          else
  790.            dem_num=-1;
  791.          break;
  792.        case ESCKEY :
  793.          LoadView(old_view);
  794.          cleanup();
  795.          exit(0);
  796.          break;
  797.        default:
  798.          dem_num=-1;
  799.          break;
  800.      }
  801.   }
  802. }
  803.  
  804. void put_back(int where)
  805. {
  806.   switch(where){
  807.     case(0):
  808.       copy_object(2,55,93,&ft_bitmap);
  809.       write_opt(0,MWHITE);
  810.       break;
  811.     case(1):
  812.       copy_object(2,169,93,&ft_bitmap);
  813.       write_opt(1,MWHITE);
  814.       break;
  815.     case(2):
  816.       copy_object(2,283,93,&ft_bitmap);
  817.       write_opt(2,MWHITE);
  818.       break;
  819.     case(3):
  820.       copy_object(2,397,93,&ft_bitmap);
  821.       write_opt(3,MWHITE);
  822.       break;
  823.     case(4):
  824.       copy_object(2,511,93,&ft_bitmap);
  825.       write_opt(4,MWHITE);
  826.       break;
  827.     default:
  828.       clean_local();
  829.       alert("Failed (put_back)\n");
  830.       break;
  831.   }
  832. }
  833.  
  834. void cleanup()
  835. {
  836. int loop;
  837.  
  838.   if(font_ptr) CloseFont(font_ptr);
  839.   if(cfontptr) CloseFont(cfontptr);
  840.   system("cpu datacache > NIL:");
  841.   al_clean();
  842.   if(keybufptr!=NULL) free(keybufptr);
  843.   FreeCprList( ft_view.LOFCprList );
  844.   FreeCprList( sec_view.LOFCprList );
  845.   FreeCprList( ft_view.SHFCprList );
  846.   FreeCprList( sec_view.SHFCprList );
  847.   FreeVPortCopLists( &ft_viewport );
  848.   FreeVPortCopLists( &sec_viewport);
  849.  
  850.   /*Because both screens are interlaced they have two seperate
  851.     copperlists, stored in the "view.SHFCprList" */
  852.  
  853.   for( loop = 0; loop < DEPTH; loop++ ){
  854.     if( ft_bitmap.Planes[ loop ] )
  855.       FreeRaster( ft_bitmap.Planes[ loop ], WIDTH, HEIGHT );
  856.   }
  857.   for( loop = 0; loop < DEPTH; loop++ ){
  858.     if( sec_bitmap.Planes[ loop ] )
  859.       FreeRaster( sec_bitmap.Planes[ loop ], WIDTH, HEIGHT );
  860.   }
  861.   for( loop = 0; loop < DEPTH; loop++ ){
  862.     if( thd_bitmap.Planes[ loop ] )
  863.       FreeRaster( thd_bitmap.Planes[ loop ], WIDTH, HEIGHT );
  864.   }
  865.   if(wb_version>=37){
  866.     if( ft_vextra ) GfxFree(ft_vextra);
  867.     if( sec_vextra ) GfxFree(sec_vextra);
  868.     if( vpone_extra) GfxFree(vpone_extra);
  869.     if( vptwo_extra) GfxFree(vptwo_extra);
  870.     if( monspec ) CloseMonitor( monspec );
  871.   }
  872.   if( ft_viewport.ColorMap != NULL ) FreeColorMap( ft_viewport.ColorMap );
  873.   if( sec_viewport.ColorMap != NULL ) FreeColorMap( sec_viewport.ColorMap );
  874.   shutdown(); /* Close Window and screen safely */
  875.   if( buffer != NULL ){
  876.      free(buffer);
  877.      buffer=NULL;
  878.   }
  879.   if( display != NULL){
  880.      free(display);
  881.      display=NULL;
  882.   }
  883.   if( aport ) {
  884.     DeleteMsgPort(aport);
  885.     aport=NULL;
  886.   }
  887.   if( ConsoleDevice != NULL) CloseDevice( (struct IORequest *) &ioreq);
  888.   if( DiskfontBase != NULL) CloseLibrary(DiskfontBase);
  889.   if( GfxBase != NULL) CloseLibrary( (struct Library *) GfxBase );
  890.   if( WorkbenchBase ) CloseLibrary(WorkbenchBase);
  891.   if( IntuitionBase != NULL ) CloseLibrary( IntuitionBase );
  892. }
  893.  
  894. /* void aquire_bits(int)
  895.  
  896.    Take the picture number as an argument and loads in
  897.    the bitmap accordingly */
  898.  
  899. void acquire_bits(int picnum)
  900. {
  901.  
  902. int aplane,aline,fh,segment;
  903. char buffer[WIDTH/8*16], *pic_file;
  904. UBYTE *bitptr=NULL;
  905. struct BitMap the_bitmap;
  906.  
  907.   switch(picnum){
  908.     case(1):
  909.       pic_file=MENUPATH;
  910.       the_bitmap = ft_bitmap;
  911.       break;
  912.     case(2):
  913.       pic_file=DEMPATH;
  914.       the_bitmap = sec_bitmap;
  915.       break;
  916.     case(3):
  917.       pic_file=DUMPPATH;
  918.       the_bitmap = thd_bitmap;
  919.       break;
  920.     default:
  921.       clean_local();
  922.       alert("Incorrect picture number label");
  923.       break;
  924.   }
  925.  
  926.   fh = open(pic_file,O_RDONLY);
  927.   if (fh<0){
  928.     clean_local();
  929.     alert("Couldn't open data file\n");
  930.   }
  931.   for(aplane=0;aplane<DEPTH;aplane++){
  932.     bitptr = (UBYTE *) (the_bitmap.Planes[aplane] );
  933.     for(segment=0;segment<HEIGHT/16;segment++){
  934.       read(fh,buffer,WIDTH*2);
  935.         for(aline=0;aline<WIDTH*2;aline++){
  936.           *bitptr++ = (UBYTE) buffer[aline];
  937.         }
  938.     }
  939.   }
  940.   close(fh);
  941. }
  942.  
  943. void copy_object(int object, long dx, long dy, struct BitMap *dest_bm)
  944. {
  945.  
  946. struct BitMap *source_bm;
  947. long sx, sy, mw, mh, flag, mask;
  948.  
  949. flag = 0xC0;  /* Normal copy */
  950. mask = 0xFF;  /* Use all bitplanes */
  951.  
  952.   switch(object){
  953.     case 1 :
  954.       /* OPTION ON */
  955.       sx = 1L;
  956.       sy = 1L;
  957.       source_bm= &thd_bitmap;
  958.       mw = 79;
  959.       mh = 53;
  960.       break;
  961.     case 2 :
  962.       /* OPTION OFF */
  963.       sx = 82L;
  964.       sy = 1L;
  965.       source_bm=&thd_bitmap;
  966.       mw = 79;
  967.       mh = 53;
  968.       break;
  969.     case 3 :
  970.       /* VARIABLE */
  971.       sx = 178L;
  972.       sy = 2L;
  973.       source_bm=&thd_bitmap;
  974.       mw = 46;
  975.       mh = 58;
  976.       break;
  977.     case 4 :
  978.       /* HOLE */
  979.       sx = 240L;
  980.       sy = 2L;
  981.       source_bm=&thd_bitmap;
  982.       mw = 53;
  983.       mh = 53;
  984.       break;
  985.     case 5 :
  986.       /* VBB */
  987.       sx = 298L;
  988.       sy = 2L;
  989.       source_bm=&thd_bitmap;
  990.       mw = 6;
  991.       mh = 18;
  992.       break;
  993.     case 6 :
  994.       /* HBB */
  995.       sx = 298L;
  996.       sy = 24L;
  997.       source_bm=&thd_bitmap;
  998.       mw = 18;
  999.       mh = 6;
  1000.       break;
  1001.     case 7 :
  1002.      /* FILL */
  1003.       sx = 307L;
  1004.       sy = 2L;
  1005.       source_bm=&thd_bitmap;
  1006.       mw = 8;
  1007.       mh = 6;
  1008.       break;
  1009.     case 8 :
  1010.     /* IAR */
  1011.       sx = 319L;
  1012.       sy = 2L;
  1013.       source_bm=&thd_bitmap;
  1014.       mw = 46;
  1015.       mh = 22;
  1016.       break;
  1017.     case 9 :
  1018.     /* IOFF */
  1019.       sx = 319L;
  1020.       sy = 29L;
  1021.       source_bm=&thd_bitmap;
  1022.       mw = 16;
  1023.       mh = 15;
  1024.       break;
  1025.     case 10 :
  1026.     /* ION */
  1027.       sx = 338L;
  1028.       sy = 29L;
  1029.       source_bm=&thd_bitmap;
  1030.       mw = 16;
  1031.       mh = 15;
  1032.       break;
  1033.     default:
  1034.       clean_local();
  1035.       alert("Object doesn't exist (copy_object)\n");
  1036.       break;
  1037.   }
  1038.   WaitBlit(); /* Make sure we have blitter */
  1039.   BltBitMap(source_bm, sx, sy, dest_bm, dx, dy, mw, mh, flag, mask, NULL);
  1040. }
  1041.  
  1042. void opttext()
  1043. {
  1044. int line, letter;
  1045. char c;
  1046. FILE *file;
  1047.  
  1048.   for(line=0;line<NUMOFOPT;line++){
  1049.      for(letter=0;letter<SLENGTH;letter++){
  1050.         choices[line][letter]='\0';
  1051.      }
  1052.   }
  1053.   line=letter=c=0;
  1054.   file=fopen(OPTTPATH,"r");
  1055.   if(file!=NULL){
  1056.     while( (c!=EOF) && (letter<SLENGTH) && (line<NUMOFOPT) ){
  1057.       c= fgetc(file);
  1058.       switch(c){
  1059.         case '\n' :
  1060.           choices[line][letter]= '\0';
  1061.           line++;
  1062.           letter=0;
  1063.           break;
  1064.         case EOF :
  1065.           break;
  1066.         default :
  1067.           choices[line][letter]= c;
  1068.           letter++;
  1069.           break;
  1070.       }
  1071.     }
  1072.     fclose(file);
  1073.   }
  1074.   else{
  1075.     clean_local();
  1076.     alert("Couldn't open options file (opttext)\n");
  1077.   }
  1078. }
  1079.  
  1080. void write_opt(int select, long color)
  1081. {
  1082. int index;
  1083.  
  1084.    index = 10 * select;
  1085.    draw_modes(0xFF,&ft_rastport,MBAGE,0L,JAM1);
  1086.    SetFont(&ft_rastport,font_ptr);
  1087.    /* Write text to option squares */
  1088.    if (color!=MWHITE){
  1089.      Move(&ft_rastport,67,113);
  1090.      Text(&ft_rastport, &choices[0][0], strlen(&choices[0][0])  );
  1091.      Move(&ft_rastport,67,126);
  1092.      Text(&ft_rastport, &choices[1][0], strlen(&choices[1][0])  );
  1093.      Move(&ft_rastport,181,113);
  1094.      Text(&ft_rastport, &choices[2][0], strlen(&choices[2][0])  );
  1095.      Move(&ft_rastport,181,126);
  1096.      Text(&ft_rastport, &choices[3][0], strlen(&choices[3][0])  );
  1097.      Move(&ft_rastport,295,113);
  1098.      Text(&ft_rastport, &choices[4][0], strlen(&choices[4][0])  );
  1099.      Move(&ft_rastport,295,126);
  1100.      Text(&ft_rastport, &choices[5][0], strlen(&choices[5][0])  );
  1101.      Move(&ft_rastport,409,113);
  1102.      Text(&ft_rastport, &choices[6][0], strlen(&choices[6][0])  );
  1103.      Move(&ft_rastport,409,126);
  1104.      Text(&ft_rastport, &choices[7][0], strlen(&choices[7][0])  );
  1105.      Move(&ft_rastport,523,113);
  1106.      Text(&ft_rastport, &choices[8][0], strlen(&choices[8][0])  );
  1107.      Move(&ft_rastport,523,126);
  1108.      Text(&ft_rastport, &choices[9][0], strlen(&choices[9][0])  );
  1109.    }
  1110.    /*Write text to key sections */
  1111.    draw_modes(0xFF,&ft_rastport,color,0L,JAM1);
  1112.    Move(&ft_rastport,158,370);
  1113.    Text(&ft_rastport,&choices[10+index][0], strlen(&choices[10+index][0]) );
  1114.    Move(&ft_rastport,158,387);
  1115.    Text(&ft_rastport,&choices[11+index][0], strlen(&choices[11+index][0]) );
  1116.    Move(&ft_rastport,331,370);
  1117.    Text(&ft_rastport,&choices[12+index][0], strlen(&choices[12+index][0]) );
  1118.    Move(&ft_rastport,331,387);
  1119.    Text(&ft_rastport,&choices[13+index][0], strlen(&choices[13+index][0]) );
  1120.    Move(&ft_rastport,504,370);
  1121.    Text(&ft_rastport,&choices[14+index][0], strlen(&choices[14+index][0]) );
  1122.    Move(&ft_rastport,504,387);
  1123.    Text(&ft_rastport,&choices[15+index][0], strlen(&choices[15+index][0]) );
  1124.    Move(&ft_rastport,158,464);
  1125.    Text(&ft_rastport,&choices[16+index][0], strlen(&choices[16+index][0]) );
  1126.    Move(&ft_rastport,158,481);
  1127.    Text(&ft_rastport,&choices[17+index][0], strlen(&choices[17+index][0]) );
  1128.    Move(&ft_rastport,331,464);
  1129.    Text(&ft_rastport,&choices[18+index][0], strlen(&choices[18+index][0]) );
  1130.    Move(&ft_rastport,331,481);
  1131.    Text(&ft_rastport,&choices[19+index][0], strlen(&choices[19+index][0]) );
  1132. }
  1133.  
  1134. void alert(char *message)
  1135. {
  1136.    open_log();
  1137.    write_file(message);
  1138.    close_file();
  1139.    perror(message);
  1140.    LoadView(old_view);
  1141.    cleanup();
  1142.    exit(20);
  1143. }
  1144.  
  1145.